﻿function FormatterState(value, row, index) {
    if (value == 1) {
        return ['报备待审'].join('');
    }
    if (value == 2) {
        return ['报备通过'].join('');
    }
    if (value == 3) {
        return ['报备驳回'].join('');
    }
    if (value == 4) {
        return ['已量尺'].join('');
    }
    if (value == 5) {
        return ['已交定金'].join('');
    }
    if (value == 6) {
        return ['已交首期工程款'].join('');
    }
    if (value == 7) {
        return ['已验收完成'].join('');
    }
    if (value == 8) {
        return ['已退'].join('');
    }
}
//星标
function FormatterstarTarget(value, row, index) {

    if (value == 0) {
        var str = "无";
        return [
      '<a class="kv-file-zoom btn btn-xs btn-default" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
      '<i">' + str + '</i>',
      '</a>  '
        ].join('');
    }
    if (value == 1) {
        var str = "客户信用不良";
        return [
      '<a href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
      '<i">' + str + '</i>',
      '</a>  '
        ].join('');
    }
    if (value == 2) {
        var str = "客户首付分期";
        return [
      '<a class="kv-file-zoom btn btn-xs btn-default" style="background-color: #55a2ed;" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
      '<i">' + str + '</i>',
      '</a>  '
        ].join('');
    }
    if (value == 3) {
        var str = "客户全款购买";
        return [
      '<a class="kv-file-zoom btn btn-xs btn-danger" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
      '<i">' + str + '</i>',
      '</a>  '
        ].join('');
    }
    if (value == 4) {
        var str = "别墅洋房";
        return [
      '<a class="kv-file-zoom btn btn-xs btn-success" style="background-color: #dc5fce;" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
      '<i">' + str + '</i>',
      '</a>  '
        ].join('');
    }
    if (value == 5) {
        var str = "其他";
        return [
      '<a class="kv-file-zoom btn btn-xs btn-warning"  href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
      '<i">' + str + '</i>',
      '</a>  '
        ].join('');
    }
}
//星标标设置
function starTargetSet(value, id) {
    parent.layer.open({
        type: 2,
        title: "星标类型",
        shadeClose: false,
        shade: 0.4,
        area: ["800px", "260px"],
        content: "/Decoration/DecorationRunnings/SetStarTarget?id=" + id,
        end: function () {
            refreshTable();
        }
    });
}

function isTrueFormatter(value, row, index) {
    return value ? '<i class="glyphicon glyphicon-ok"></i>' : '<i class="glyphicon glyphicon-remove"></i>'
}

//获取表格高度
function getHeight() {
    return $(window).height() - 150;
}

//重置表格高度
setTimeout(function () {
    $table.bootstrapTable('resetView');
}, 200);

//重置表格高度
$(window).resize(function () {
    $table.bootstrapTable('resetView', {
        height: getHeight()
    });
});
//搜索按钮
$('#searchBtn').click(function (e) {
    $table.bootstrapTable('refresh');
});
//图片管理
function PictureManagementFormatter(value, row, index) {
    if (parseInt(row['imageCount1']) == 0) {
        return [
        '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData(' + row.id + ')"  title="带看单管理">',
        '<i class="glyphicon glyphicon-upload"></i>',
        '</a>  '
        ].join('');
    } else {
        return [
        '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData(' + row.id + ')" title="带看单管理">',
        '<i class="glyphicon glyphicon-picture"></i>',
        '×' + row['imageCount1'],
        '</a>  '
        ].join('');
    }

    //return [
    //    '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="PictureManagementeditData(' + row.id + ')">',
    //    '带看单管理',
    //    '</a>  ',
    //].join('');
}
function PictureManagementeditData(id) {
    parent.layer.open({
        type: 2,
        title: '添加图片',
        shadeClose: false,
        shade: 0.4,
        area: ['960px', '750px'],
        content: '/Images/Index?GroupID=' + 7 + '&InterfixID=' + id + '&ImageType=' + 1,
        end: function () {
            refreshTable();
        }
    });
}
//成交协议图片管理
function PictureManagement2Formatter(value, row, index) {

    if (parseInt(row['imageCount2']) == 0) {
        return [
        '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData2(' + row.id + ')"  title="成交协议">',
        '<i class="glyphicon glyphicon-upload"></i>',
        '</a>  '
        ].join('');
    } else {
        return [
        '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData2(' + row.id + ')" title="成交协议">',
        '<i class="glyphicon glyphicon-picture"></i>',
        '×' + row['imageCount2'],
        '</a>  '
        ].join('');
    }

    //return [
    //    '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="PictureManagementeditData2(' + row.id + ')">',
    //    '成交协议',
    //    '</a>  ',
    //].join('');
}
function PictureManagementeditData2(id) {
    parent.layer.open({
        type: 2,
        title: '添加图片',
        shadeClose: false,
        shade: 0.4,
        area: ['960px', '750px'],
        content: '/Images/Index?GroupID=' + 7 + '&InterfixID=' + id + '&ImageType=' + 2,
        end: function () {
            refreshTable();
        }
    });
}
//首付图片管理
function PictureManagement3Formatter(value, row, index) {

    if (parseInt(row['imageCount3']) == 0) {
        return [
        '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData3(' + row.id + ')"  title="首付图片">',
        '<i class="glyphicon glyphicon-upload"></i>',
        '</a>  '
        ].join('');
    } else {
        return [
        '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData3(' + row.id + ')" title="首付图片">',
        '<i class="glyphicon glyphicon-picture"></i>',
        '×' + row['imageCount3'],
        '</a>  '
        ].join('');
    }

    //return [
    //    '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="PictureManagementeditData3(' + row.id + ')">',
    //    '首付图片',
    //    '</a>  ',
    //].join('');
}
function PictureManagementeditData3(id) {
    parent.layer.open({
        type: 2,
        title: '添加图片',
        shadeClose: false,
        shade: 0.4,
        area: ['960px', '750px'],
        content: '/Images/Index?GroupID=' + 7 + '&InterfixID=' + id + '&ImageType=' + 3,
        end: function () {
            refreshTable();
        }
    });
}